﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageFlowTime : Objective
    {
        public AverageFlowTime()
            :base()
        {
        }
        public AverageFlowTime(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageFlowTime = 0;
            double totalFlowTime = 0;

            int flowTime = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                flowTime = order.EndDate - order.ReleaseDate;
                totalFlowTime = totalFlowTime + flowTime;
            }

            averageFlowTime = totalFlowTime / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageFlowTime,2);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderReleaseDateValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
        }

        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Flow Time";
                aboutInfo.Guid = new Guid("{294FD8F0-BFC2-45e8-9643-4366E16F1001}");
                aboutInfo.Description = Resources.AverageFlowTimeDescription;
                return aboutInfo;
            }
        }

    }
}
